package com.hy.proxy.core;


import com.hy.proxy.core.entity.Proxy;
import com.hy.proxy.core.entity.SSR;
import com.hy.proxy.core.util.Site;
import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Encoder;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;


/**
 * @Author: hy
 * @Date: Created in 2019/9/20/16:48
 * @Description:
 * @Version: 1.0
 */
@Slf4j
public class ProxySiteTest {

    public volatile static boolean R1 = true;
    public volatile static boolean R2 = true;
    public volatile static boolean R3 = true;
    public volatile static boolean R4 = true;

    public static void main(String[] args) {

        System.out.println("-----start");

        Runnable r1 = () -> {
            Site.sendRequestByFreeV2ray();
            R1 = false;
        };

        Runnable r2 = () -> {
            Site.sendRequestByFreeSs(Proxy.ProxyType.SS);
            R2 = false;
        };

        Runnable r3 = () -> {
            Site.sendRequestBySsrTool();
            R3 = false;
        };

        Runnable r4 = () -> {

            while (R1 || R2 || R3) {

            }

            System.out.println("------------");
            System.out.println(Site.v2List.size());
            Site.v2List.forEach((e) -> System.out.println(e.toString()));
            System.out.println("------------");
            System.out.println(Site.ssrList.size());
            Site.ssrList.forEach((e) -> System.out.println(e.toString()));
            System.out.println("------------");
            System.out.println(Site.ssList.size());
            Site.ssList.forEach((e) -> System.out.println(e.toString()));
            System.out.println("-----finish");

            StringBuffer stringBuffer = new StringBuffer();

            for (Proxy ssr : Site.ssrList) {
                stringBuffer.append(((SSR) ssr).getSsrLink());

            }

            try {
                Writer writer = new FileWriter("d:\\ssr.txt");
                writer.write(new BASE64Encoder().encodeBuffer(stringBuffer.toString().getBytes()));
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        };

        new Thread(r1).start();
        new Thread(r2).start();
        new Thread(r3).start();
        new Thread(r4).start();

    }


}
